package com.example.com.common.app;

import android.content.Context;

/**
 * MVP模式中的基础p层
 * Created by ChenYiYao on 2018/2/1.
 */

public class BasePresenter<T extends BaseContract.View> implements BaseContract.Presenter {
    protected T mView;

    public Context context;
    public BasePresenter(T view) {
        setView(view);
    }

    @Override
    public void start() {

    }

    @Override
    public void destroy() {
        T view = mView;
        mView = null;
        if (view != null) {
            // 把Presenter设置为NULL
            view.setPresenter(null);
        }
    }

    /**
     * 给子类获取view，进行操作
     * 不允许覆写
     *
     * @return View
     */
    public final T getView() {
        return mView;
    }

    /**
     * 设置一个View，子类可以复写
     */
    public void setView(T view) {
        this.mView = view;
        //同时将presenter关联到view中
        this.mView.setPresenter(this);
    }
}
